package com.ubtechinc.cruzr.launcher2.model.helper;

import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;

public abstract class  SimpleFlowableOnSubscribe<T> implements FlowableOnSubscribe<T> {

    @Override
    public void subscribe(FlowableEmitter<T> e) throws Exception {
        try {
            T t = callNext();
            if (!e.isCancelled()) {
                e.onNext(t);
                e.onComplete();
            }
        } catch (Exception e1) {
            e1.printStackTrace();
            if (!e.isCancelled()) {
                e.onError(e1);
            }
        }
    }

    public abstract T callNext() throws Exception;
}
